package cj.web.admin.dao;
/*
 *  
 *  
*/
import java.util.List;
import java.util.Map;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.admin.domain.Survey;

/**
 * 
 * @author 
 *
 */
@DAO
public interface SurveyDAO{
	
	@SQL("SELECT * FROM Survey WHERE deleteFlag=1 ")
    List<Survey> queryAll();
	
	@SQL("SELECT * FROM Survey WHERE deleteFlag=1 #if(:t.name!=''){AND name like '%##(:t.name)%' } ORDER BY updateAt DESC LIMIT :t.start,:t.length ")
    List<Survey> query(@SQLParam("t") Survey vote);
	
	@SQL("SELECT count(*) FROM Survey WHERE deleteFlag=1 #if(:t.name!=''){AND name like '%##(:t.name)%' } ")
    int querysize(@SQLParam("t") Survey vote);
    
    @SQL("SELECT * FROM Survey WHERE id=:1")
    Survey queryById(int id);
    
    @SQL("INSERT INTO Survey (type,name,descs,choiceCount,choiceFraction,judgementCount,judgementFraction,multiSelectCount,multiSelectFraction,surveyDepotId,voteStart,voteEnd,deleteFlag,createUser,createAt,updateUser,updateAt,ksAt) VALUES (:t.type,:t.name,:t.descs,:t.choiceCount,:t.choiceFraction,:t.judgementCount,:t.judgementFraction,:t.multiSelectCount,:t.multiSelectFraction,:t.surveyDepotId,:t.voteStart,:t.voteEnd,1,:t.createUser,now(),:t.updateUser,now(),:t.ksAt)")
    void create(@SQLParam("t") Survey vote);
	
	@SQL("UPDATE Survey SET type=:t.type,name=:t.name,descs=:t.descs,choiceFraction=:t.choiceFraction,judgementFraction=:t.judgementFraction,multiSelectFraction=:t.multiSelectFraction,choiceCount=:t.choiceCount,judgementCount=:t.judgementCount,multiSelectCount=:t.multiSelectCount,surveyDepotId=:t.surveyDepotId,voteStart=:t.voteStart,voteEnd=:t.voteEnd,updateUser=:t.updateUser,updateAt=now(),ksAt=:t.ksAt WHERE id=:t.id")
    void update(@SQLParam("t") Survey vote);
    
    @SQL("UPDATE Survey SET deleteFlag=0 WHERE id=:1")
    void deleteById(int id);

    @SQL("select id,descs from Survey where deleteFlag=1 and voteEnd > NOW()")
	List<Map> vldtVote();
}